var mongoose = require('mongoose')
var db = require('../../server/db')

var modelName = 'post'

var schema = new mongoose.Schema({
    handler: {
        id: mongoose.Schema.ObjectId,
        name: {type: String, default: ''}
    },
    title: {type: String, default: ''},
    content:{type: String, default: ''},
    comments: [{
        handler:{
            id: mongoose.Schema.ObjectId,
            name: {type: String, default: ''}
        },
        targeter: {
            id: mongoose.Schema.ObjectId,
            name: {type: String, default: ''}
        },
        content: {type: String, default: ''},
        createdAt: {type: Date, default: new Date()},
        comments: [
            {
                handler:{
                    id: mongoose.Schema.ObjectId,
                    name: {type: String, default: ''}
                },
                targeter: {
                    id: mongoose.Schema.ObjectId,
                    name: {type: String, default: ''}
                },
                content: {type: String, default: ''},
                createdAt: {type: Date, default: new Date()}
            }
        ]
    }],
    commentCount: {type: Number, default: 0},
    readCount: {type: Number, default: 0},
    collect: [{
        id: mongoose.Schema.ObjectId,
        name: {type: String, default: ''}
    }]
}, {timestamps: true})

var model = db.model(modelName, schema)


module.exports = model